﻿using PlantsZombies.Common.Card;
using System.Collections.Generic;
using System;
using System.Drawing;
using System.Reflection;
using System.Linq;
using System.Runtime.Remoting.Metadata;
using PlantsZombies.Common.Bullet;
using System.IO;

namespace PlantsZombies.Common
{
    /// <summary>
    /// 加载资源文件
    /// </summary>
    public unsafe partial class GameCenter
    {
        private void Init()
        {
            SetSunflowerImage();
            SetSunflowerBullet();
            SetPeaShooterImage();
            SetPeabulletImage();
            SetOrdinaryZombieImage();
            SetSupportRodZombie();
            SetOliveZombie();
            SetSharpshooter();
            SetBitmapsIkun();
            SetBitmapsBasketball();
            SetBitmapsSunWuKong();
            //SetBitmapsSunWuKongBullet();
            SetBitmapsLongBullet();
            SetBitmapsZhangFeiBullet();
            SetBitmapsZhangFei();
            SetBitmapsGeBuLin();
            SetBitmapsGeBuLin2();
            SetBitmapsFaShi();
            SetBitmapsFaShiBullet4();

            InitCards();

        }

        #region 卡片
        private ImageObject _sunflowerCard;// 向日葵
        private ImageObject _peaShooterCard;// 豌豆射手
        private ImageObject _shovelCard;// 铁铲
        private ImageObject _sharpshooterCard;// 神枪手
        private ImageObject _ikunCard;// ikun
        private ImageObject _sunwukongCard;// 孙悟空
        private ImageObject _zhangfeiCard;// 张飞
        private ImageObject _fashiCard;// 张飞


        private void InitCards()
        {
            _sunflowerCard = new ImageObject(Properties.Resources.sunflowerCard);
            _peaShooterCard = new ImageObject(Properties.Resources.PeaShooterCaard);
            _shovelCard = new ImageObject(Properties.Resources.shovel);
            _sharpshooterCard = new ImageObject(Properties.Resources.sharpshooterCard);
            _ikunCard = new ImageObject(Properties.Resources.ikunCard);
            _sunwukongCard = new ImageObject(Properties.Resources.sunwukongCard);
            _zhangfeiCard= new ImageObject(Properties.Resources.zhangfeiCard);
            _fashiCard = new ImageObject(Properties.Resources.Master0);

            List<CardObject> cardObjects= new List<CardObject>();
            Size cardSize = new Size(70, 44);

            GamePlantCard gamePlantCard1 = new GamePlantCard(_sunflowerCard, SpeciesType.Sunflower, cardSize);
            gamePlantCard1.CardPrice = 20;
            GamePlantCard gamePlantCard2 = new GamePlantCard(_peaShooterCard, SpeciesType.PeaShooter, cardSize);
            gamePlantCard2.CardPrice = 30;
            GamePlantCard gamePlantCard3 = new GamePlantCard(_sharpshooterCard, SpeciesType.Sharpshooter, cardSize);
            gamePlantCard3.CardPrice = 50;
            GamePlantCard gamePlantCard4 = new GamePlantCard(_ikunCard, SpeciesType.IKun, cardSize);
            gamePlantCard4.CardPrice = 40;
            GameRemoveCard gamePlantCard5 = new GameRemoveCard(_shovelCard, SpeciesType.Shove, cardSize);
            GamePlantCard gamePlantCard6= new GamePlantCard(_sunwukongCard, SpeciesType.SunWuKong, cardSize);
            gamePlantCard6.CardPrice = 60;
            GamePlantCard gamePlantCard7 = new GamePlantCard(_zhangfeiCard, SpeciesType.ZhangFei, cardSize);
            gamePlantCard7.CardPrice = 60;
            GamePlantCard gamePlantCard8 = new GamePlantCard(_fashiCard, SpeciesType.FaShi, cardSize);
            gamePlantCard8.CardPrice = 80;

            cardObjects.Add(gamePlantCard1);
            cardObjects.Add(gamePlantCard2);
            cardObjects.Add(gamePlantCard3);
            cardObjects.Add(gamePlantCard4);
            cardObjects.Add(gamePlantCard5);
            cardObjects.Add(gamePlantCard6);
            cardObjects.Add(gamePlantCard7);
            cardObjects.Add(gamePlantCard8);

            var cardArray = cardObjects.ToArray();
            fixed (CardObject* cardPtr = cardArray)
            {
                for (int i = 0; i < cardArray.Length; i++)
                {
                    CardObject* ptr = cardPtr + i;
                    ptr->DrawCardCallback += GamePlantCard_DrawCardCallback;
                }
            }
            _gameCardTool.SetCards(cardArray);
        }
        public ImageObject SunflowerCard { get { return _sunflowerCard; } }
        public ImageObject PeaShooterCard { get { return _peaShooterCard; } }
        public ImageObject ShovelCard { get { return _shovelCard; } }
        public ImageObject SharpshooterCard { get { return _sharpshooterCard; } }
        #endregion

        #region 设置图像
        [PlantZombie(SpeciesType.Sunflower, BodyWeapon.Body)]
        private ImageObject[] _bitmapsSunflower;// 向日葵
        [PlantZombie(SpeciesType.Sunflower, BodyWeapon.Weapon)]
        public ImageObject[] _bitmapsSunflowerBullet;// 太阳花
        [PlantZombie(SpeciesType.PeaShooter, BodyWeapon.Body)]
        private ImageObject[] _bitmapsPeaShooter;// 豌豆射手
        [PlantZombie(SpeciesType.PeaShooter, BodyWeapon.Weapon)]
        private ImageObject[] _bitmapsPeabullet;// 豌豆射手子弹
        [PlantZombie(SpeciesType.Sharpshooter, BodyWeapon.All)]
        private ImageObject[] _bitmapsSharpshooter;// 神枪手
        [PlantZombie(SpeciesType.IKun, BodyWeapon.Body)]
        private ImageObject[] _bitmapsIkun;// Ikun
        [PlantZombie(SpeciesType.IKun, BodyWeapon.Weapon)]
        private ImageObject[] _bitmapsBasketball;// 篮球
        [PlantZombie(SpeciesType.SunWuKong, BodyWeapon.Body)]
        private ImageObject[] _bitmapsSunWuKong;// 孙悟空
        //[PlantZombie(SpeciesType.SunWuKong, BodyWeapon.Weapon)]
        //private ImageObject[] _bitmapsSunWuKongBullet;// 火焰
        [PlantZombie(SpeciesType.SunWuKong, BodyWeapon.Weapon)]
        private ImageObject[] _bitmapsLongBullet;// 龙

        // 张飞
        [PlantZombie(SpeciesType.ZhangFei, BodyWeapon.Body)]
        private ImageObject[] _bitmapsZhangFei;
        [PlantZombie(SpeciesType.ZhangFei, BodyWeapon.Weapon)]
        private ImageObject[] _bitmapsZhangFeiBullet;

        // 法师
        [PlantZombie(SpeciesType.FaShi, BodyWeapon.Body)]
        private ImageObject[] _bitmapsFaShi;
        [PlantZombie(SpeciesType.FaShi, BodyWeapon.Weapon)]
        private ImageObject[] _bitmapsFaShiBullet;


        [PlantZombie(SpeciesType.OrdinaryZombie, BodyWeapon.Body)]
        private ImageObject[] _bitmapsOrdinaryZombie;// 普通僵尸
        [PlantZombie(SpeciesType.SupportRodZombie, BodyWeapon.Body)]
        private ImageObject[] _bitmapsSupportRodZombie;// 超级僵尸
        [PlantZombie(SpeciesType.OliveZombie, BodyWeapon.Body)]
        private ImageObject[] _bitmapsOliveZombie;// 橄榄僵尸
        [PlantZombie(SpeciesType.GeBuLin, BodyWeapon.Body)]
        private ImageObject[] _bitmapsGeBuLin;// 哥布林
        [PlantZombie(SpeciesType.GeBuLin2, BodyWeapon.Body)]
        private ImageObject[] _bitmapsGeBuLin2;// 哥布林2
        private void SetBitmapsFaShiBullet4()
        {
            var b3 = SetBitmapsFaShiBullet3();
            var b2 = SetBitmapsFaShiBullet2();
            var b = SetBitmapsFaShiBullet();

            ImageObject[] arr = new ImageObject[b3.Length + b2.Length + b.Length];
            Array.Copy(b3, arr, b3.Length);
            Array.Copy(b2, 0, arr, b3.Length, b2.Length);
            Array.Copy(b, 0, arr, b3.Length + b2.Length, b.Length);
            _bitmapsFaShiBullet = arr;
        }

        private ImageObject[] SetBitmapsFaShiBullet3()
        {
            Bitmap[] bullets = { Properties.Resources.GhostCatching0, Properties.Resources.GhostCatching1, Properties.Resources.GhostCatching2, Properties.Resources.GhostCatching3, Properties.Resources.GhostCatching4, Properties.Resources.GhostCatching5, Properties.Resources.GhostCatching6, Properties.Resources.GhostCatching7, Properties.Resources.GhostCatching8, Properties.Resources.GhostCatching9, Properties.Resources.GhostCatching10, Properties.Resources.GhostCatching11, Properties.Resources.GhostCatching12, Properties.Resources.GhostCatching13, Properties.Resources.GhostCatching14, Properties.Resources.GhostCatching15, Properties.Resources.GhostCatching16, Properties.Resources.GhostCatching17, Properties.Resources.GhostCatching18, Properties.Resources.GhostCatching19 };
            return SetImage(bullets);
        }
        private ImageObject[] SetBitmapsFaShiBullet2()
        {
            Bitmap[] bullets = { Properties.Resources.spirit0, Properties.Resources.spirit1, Properties.Resources.spirit2, Properties.Resources.spirit3, Properties.Resources.spirit4, Properties.Resources.spirit5 };
            return SetImage(bullets);
        }
        private ImageObject[] SetBitmapsFaShiBullet()
        {
            Bitmap[] bullets = { Properties.Resources.feng0, Properties.Resources.feng1, Properties.Resources.feng2, Properties.Resources.feng3, Properties.Resources.feng4, Properties.Resources.feng5 };
            return SetImage(bullets);
        }
        private void SetBitmapsFaShi()
        {
            Bitmap[] bullets = { Properties.Resources.Master0, Properties.Resources.Master1, Properties.Resources.Master2, Properties.Resources.Master3, Properties.Resources.Master4, Properties.Resources.Master5, Properties.Resources.Master6, Properties.Resources.Master7, Properties.Resources.Master8, Properties.Resources.Master9, Properties.Resources.Master10, Properties.Resources.Master11, Properties.Resources.Master12, Properties.Resources.Master13, Properties.Resources.Master14, Properties.Resources.Master15, Properties.Resources.Master16, Properties.Resources.Master17, Properties.Resources.Master18, Properties.Resources.Master19, Properties.Resources.Master20, Properties.Resources.Master21, Properties.Resources.Master22, Properties.Resources.Master23, Properties.Resources.Master24, Properties.Resources.Master25, Properties.Resources.Master26, Properties.Resources.Master27, Properties.Resources.Master28, Properties.Resources.Master29, Properties.Resources.Master30, Properties.Resources.Master31, Properties.Resources.Master32, Properties.Resources.Master33, Properties.Resources.Master34, Properties.Resources.Master35, Properties.Resources.Master36, Properties.Resources.Master37 };
            _bitmapsFaShi = SetImage(bullets);
        }
        private void SetBitmapsGeBuLin2()
        {
            Bitmap[] bullets = { Properties.Resources.gebulin20, Properties.Resources.gebulin21, Properties.Resources.gebulin22, Properties.Resources.gebulin23, Properties.Resources.gebulin24, Properties.Resources.gebulin25, Properties.Resources.gebulin26, Properties.Resources.gebulin27 };
            _bitmapsGeBuLin2 = SetImage(bullets);
        }
        private void SetBitmapsGeBuLin()
        {
            Bitmap[] bullets = { Properties.Resources.gebulin0__1_, Properties.Resources.gebulin0__2_ , Properties.Resources.gebulin0__3_, Properties.Resources.gebulin0__4_, Properties.Resources.gebulin0__5_ };
            _bitmapsGeBuLin = SetImage(bullets);
        }
        private void SetBitmapsZhangFeiBullet()
        {
            Bitmap[] bullets = { Properties.Resources.zhangfeiBullet1, Properties.Resources.zhangfeiBullet2, Properties.Resources.zhangfeiBullet3, Properties.Resources.zhangfeiBullet4, Properties.Resources.zhangfeiBullet5, Properties.Resources.zhangfeiBullet6, Properties.Resources.zhangfeiBullet7, Properties.Resources.zhangfeiBullet8, Properties.Resources.zhangfeiBullet9, Properties.Resources.zhangfeiBullet10, Properties.Resources.zhangfeiBullet11, Properties.Resources.zhangfeiBullet12, Properties.Resources.zhangfeiBullet13, Properties.Resources.zhangfeiBullet14, Properties.Resources.zhangfeiBullet15, Properties.Resources.zhangfeiBullet16};
            _bitmapsZhangFeiBullet = SetImage(bullets);
        }
        private void SetBitmapsZhangFei()
        {
            Bitmap[] bullets = { Properties.Resources.zhangfei0, Properties.Resources.zhangfei1, Properties.Resources.zhangfei2, Properties.Resources.zhangfei3, Properties.Resources.zhangfei4, Properties.Resources.zhangfei5, Properties.Resources.zhangfei6, Properties.Resources.zhangfei7, Properties.Resources.zhangfei8, Properties.Resources.zhangfei9, Properties.Resources.zhangfei10, Properties.Resources.zhangfei11, Properties.Resources.zhangfei12, Properties.Resources.zhangfei13, Properties.Resources.zhangfei14, Properties.Resources.zhangfei15, Properties.Resources.zhangfei16, Properties.Resources.zhangfei17, Properties.Resources.zhangfei18, Properties.Resources.zhangfei19, Properties.Resources.zhangfei20, Properties.Resources.zhangfei21, Properties.Resources.zhangfei22, Properties.Resources.zhangfei23, Properties.Resources.zhangfei24, Properties.Resources.zhangfei25, Properties.Resources.zhangfei26, Properties.Resources.zhangfei27, Properties.Resources.zhangfei28 };
            _bitmapsZhangFei = SetImage(bullets);
        }
        private void SetBitmapsLongBullet()
        {
            Bitmap[] bullets = { Properties.Resources.long0, Properties.Resources.long1, Properties.Resources.long2, Properties.Resources.long3, Properties.Resources.long4, Properties.Resources.long5, Properties.Resources.long6, Properties.Resources.long7, Properties.Resources.long8, Properties.Resources.long9, Properties.Resources.long10, Properties.Resources.long11, Properties.Resources.long12, Properties.Resources.long13, Properties.Resources.long14, Properties.Resources.long15, Properties.Resources.long16 };
            _bitmapsLongBullet = SetImage(bullets);
        }
        private void SetBitmapsSunWuKongBullet()
        {
            Bitmap[] bullets = { Properties.Resources.sunwukongBullet0, Properties.Resources.sunwukongBullet1, Properties.Resources.sunwukongBullet2, Properties.Resources.sunwukongBullet3, Properties.Resources.sunwukongBullet4, Properties.Resources.sunwukongBullet5, Properties.Resources.sunwukongBullet6, Properties.Resources.sunwukongBullet7, Properties.Resources.sunwukongBullet8, Properties.Resources.sunwukongBullet9, Properties.Resources.sunwukongBullet10, Properties.Resources.sunwukongBullet11, Properties.Resources.sunwukongBullet12, Properties.Resources.sunwukongBullet13, Properties.Resources.sunwukongBullet14, Properties.Resources.sunwukongBullet15, Properties.Resources.sunwukongBullet16, Properties.Resources.sunwukongBullet17, Properties.Resources.sunwukongBullet18, Properties.Resources.sunwukongBullet19 };
            //_bitmapsSunWuKongBullet = SetImage(bullets);
        }
        private void SetBitmapsSunWuKong()
        {
            Bitmap[] bullets = { Properties.Resources.sunwukong0, Properties.Resources.sunwukong1, Properties.Resources.sunwukong3, Properties.Resources.sunwukong4, Properties.Resources.sunwukong5, Properties.Resources.sunwukong6, Properties.Resources.sunwukong7, Properties.Resources.sunwukong8, Properties.Resources.sunwukong9, Properties.Resources.sunwukong10, Properties.Resources.sunwukong11, Properties.Resources.sunwukong12, Properties.Resources.sunwukong13, Properties.Resources.sunwukong14, Properties.Resources.sunwukong15, Properties.Resources.sunwukong16, Properties.Resources.sunwukong17, Properties.Resources.sunwukong18, Properties.Resources.sunwukong19, Properties.Resources.sunwukong20, Properties.Resources.sunwukong21, Properties.Resources.sunwukong22, Properties.Resources.sunwukong23, Properties.Resources.sunwukong24, Properties.Resources.sunwukong25, Properties.Resources.sunwukong26, Properties.Resources.sunwukong27 };
            _bitmapsSunWuKong = SetImage(bullets);
        }
        private void SetBitmapsBasketball()
        {
            Bitmap[] bullets = { Properties.Resources.basketball};
            _bitmapsBasketball = SetImage(bullets);
        }
        private void SetBitmapsIkun()
        {
            Bitmap[] bullets = { Properties.Resources.ikun0,Properties.Resources.ikun1, Properties.Resources.ikun2, Properties.Resources.ikun3, Properties.Resources.ikun4, Properties.Resources.ikun5, Properties.Resources.ikun6, Properties.Resources.ikun7, Properties.Resources.ikun8, Properties.Resources.ikun9, Properties.Resources.ikun10, Properties.Resources.ikun11, Properties.Resources.ikun12, Properties.Resources.ikun13, Properties.Resources.ikun14, Properties.Resources.ikun15, Properties.Resources.ikun16, Properties.Resources.ikun17, Properties.Resources.ikun18, Properties.Resources.ikun19, Properties.Resources.ikun20, Properties.Resources.ikun21 };
            _bitmapsIkun = SetImage(bullets);
        }
        private void SetSunflowerImage()
        {
            Bitmap[] suns ={
                Properties.Resources.sun0, Properties.Resources.sun1, Properties.Resources.sun2, Properties.Resources.sun3, Properties.Resources.sun4,
            Properties.Resources.sun5,Properties.Resources.sun6,Properties.Resources.sun7,Properties.Resources.sun8,Properties.Resources.sun9,
                Properties.Resources.sun10,Properties.Resources.sun11,Properties.Resources.sun12,Properties.Resources.sun13,Properties.Resources.sun14,
                Properties.Resources.sun15,Properties.Resources.sun16,Properties.Resources.sun17,Properties.Resources.sun18};
            _bitmapsSunflower = SetImage(suns);
        }
        private void SetSunflowerBullet()
        {
            Bitmap[] sunBullet = { Properties.Resources.Sunlight0, Properties.Resources.Sunlight1, Properties.Resources.Sunlight2, Properties.Resources.Sunlight3
            , Properties.Resources.Sunlight4, Properties.Resources.Sunlight5, Properties.Resources.Sunlight6, Properties.Resources.Sunlight7, Properties.Resources.Sunlight8, Properties.Resources.Sunlight9, Properties.Resources.Sunlight10, Properties.Resources.Sunlight11, Properties.Resources.Sunlight12, Properties.Resources.Sunlight13, Properties.Resources.Sunlight14, Properties.Resources.Sunlight15, Properties.Resources.Sunlight16, Properties.Resources.Sunlight17, Properties.Resources.Sunlight18, Properties.Resources.Sunlight19, Properties.Resources.Sunlight20, Properties.Resources.Sunlight21, Properties.Resources.Sunlight22, Properties.Resources.Sunlight23, Properties.Resources.Sunlight24, Properties.Resources.Sunlight25, Properties.Resources.Sunlight26, Properties.Resources.Sunlight27, Properties.Resources.Sunlight28, Properties.Resources.Sunlight29};
            _bitmapsSunflowerBullet = SetImage(sunBullet);
        }
        private void SetPeaShooterImage()
        {
            Bitmap[] bitmaps = { Properties.Resources.PeaShooter0, Properties.Resources.PeaShooter1, Properties.Resources.PeaShooter2, Properties.Resources.PeaShooter3, Properties.Resources.PeaShooter4, Properties.Resources.PeaShooter5, Properties.Resources.PeaShooter6, Properties.Resources.PeaShooter7, Properties.Resources.PeaShooter8, Properties.Resources.PeaShooter9, Properties.Resources.PeaShooter10, Properties.Resources.PeaShooter11, Properties.Resources.PeaShooter12, Properties.Resources.PeaShooter13, Properties.Resources.PeaShooter14 };
            _bitmapsPeaShooter = SetImage(bitmaps);
        }
        private void SetPeabulletImage()
        {
            Bitmap[] bitmaps = { Properties.Resources.peabullet };
            _bitmapsPeabullet = SetImage(bitmaps);
        }
        private void SetOrdinaryZombieImage()
        {
            Bitmap[] bitmaps = { Properties.Resources.OrdinaryZombie0, Properties.Resources.OrdinaryZombie1, Properties.Resources.OrdinaryZombie2, Properties.Resources.OrdinaryZombie3, Properties.Resources.OrdinaryZombie4, Properties.Resources.OrdinaryZombie5, Properties.Resources.OrdinaryZombie6, Properties.Resources.OrdinaryZombie7, Properties.Resources.OrdinaryZombie8, Properties.Resources.OrdinaryZombie9, Properties.Resources.OrdinaryZombie10, Properties.Resources.OrdinaryZombie11, Properties.Resources.OrdinaryZombie12, Properties.Resources.OrdinaryZombie13, Properties.Resources.OrdinaryZombie14 };
            _bitmapsOrdinaryZombie = SetImage(bitmaps);
        }
        private void SetSupportRodZombie()
        {
            Bitmap[] bitmaps = { Properties.Resources.SupportRodZombie0, Properties.Resources.SupportRodZombie1, Properties.Resources.SupportRodZombie2, Properties.Resources.SupportRodZombie3, Properties.Resources.SupportRodZombie4, Properties.Resources.SupportRodZombie5, Properties.Resources.SupportRodZombie6, Properties.Resources.SupportRodZombie7, Properties.Resources.SupportRodZombie8, Properties.Resources.SupportRodZombie9 };
            _bitmapsSupportRodZombie = SetImage(bitmaps);
        }
        private void SetOliveZombie()
        {
            Bitmap[] bitmaps = { Properties.Resources.OliveZombie0, Properties.Resources.OliveZombie1, Properties.Resources.OliveZombie2, Properties.Resources.OliveZombie3, Properties.Resources.OliveZombie4, Properties.Resources.OliveZombie5, Properties.Resources.OliveZombie6, Properties.Resources.OliveZombie7, Properties.Resources.OliveZombie8, Properties.Resources.OliveZombie9, Properties.Resources.OliveZombie10, Properties.Resources.OliveZombie11, Properties.Resources.OliveZombie12, Properties.Resources.OliveZombie13, Properties.Resources.OliveZombie14, Properties.Resources.OliveZombie15, Properties.Resources.OliveZombie16, Properties.Resources.OliveZombie17, Properties.Resources.OliveZombie18, Properties.Resources.OliveZombie19, Properties.Resources.OliveZombie20, Properties.Resources.OliveZombie21, Properties.Resources.OliveZombie22, Properties.Resources.OliveZombie23, Properties.Resources.OliveZombie24, Properties.Resources.OliveZombie25, Properties.Resources.OliveZombie26, Properties.Resources.OliveZombie27, Properties.Resources.OliveZombie28, Properties.Resources.OliveZombie29 };
            _bitmapsOliveZombie = SetImage(bitmaps);
        }
        private void SetSharpshooter()
        {
            Bitmap[] bitmaps = { Properties.Resources.sharpshooterCard0, Properties.Resources.sharpshooterCard1, Properties.Resources.sharpshooterCard2, Properties.Resources.sharpshooterCard3, Properties.Resources.sharpshooterCard4, Properties.Resources.sharpshooterCard5, Properties.Resources.sharpshooterCard6, Properties.Resources.sharpshooterCard7, Properties.Resources.sharpshooterCard8, Properties.Resources.sharpshooterCard9, Properties.Resources.sharpshooterCard10, Properties.Resources.sharpshooterCard11 };
            _bitmapsSharpshooter = SetImage(bitmaps);
        }
        public ImageObject[] SetImage(Bitmap[] iamges)
        {
            fixed (Bitmap* ptr = iamges)
            {
                ImageObject[] ib = new ImageObject[iamges.Length];
                fixed (ImageObject* sp = ib)
                {
                    for (int i = 0; i < iamges.Length; i++)
                    {
                        *(sp + i) = new ImageObject(*(ptr + i));
                    }
                }
                return ib;
            }
        }
        #endregion

        #region 加载类
        private Dictionary<SpeciesType, Type> _plantZombieType;
        private Dictionary<SpeciesType, Type> _bulletType;
        private Dictionary<SpeciesType, List<FieldsEntity>> _imageType;
        private void InitPlantZombie()
        {
            Assembly currentAssembly = Assembly.GetEntryAssembly();
            Type attributeType = typeof(PlantZombieAttribute);
            Type gameObjectType = typeof(GameObject);
            Type bulletObjectType = typeof(BulletObject);
            Type centerType = this.GetType();

            var fields = centerType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
              .Where(f => f.GetCustomAttributes(attributeType, false).Length > 0).ToArray();
            fixed(FieldInfo* ptr= fields)
            {
                _imageType = new Dictionary<SpeciesType, List<FieldsEntity>>();
                for (int i = 0; i < fields.Length; i++)
                {
                    var t= fields[i];
                    PlantZombieAttribute sa = t.GetCustomAttributes(attributeType, false)[0] as PlantZombieAttribute;
                    if(_imageType.ContainsKey(sa.SpeciesType))
                    {
                        _imageType[sa.SpeciesType].Add(new FieldsEntity
                        {
                            BodyWeapon = sa.BodyWeapon,
                            Data = t.GetValue(this) as ImageObject[]
                        });
                    }
                    else
                    {
                        _imageType[sa.SpeciesType] = new List<FieldsEntity>()
                        {
                            new FieldsEntity
                            {
                                BodyWeapon = sa.BodyWeapon,
                                Data = t.GetValue(this) as ImageObject[]
                            }
                        };
                    }
                }
            }

            _plantZombieType = RegisterType(currentAssembly, gameObjectType, attributeType);
            _bulletType= RegisterType(currentAssembly, bulletObjectType, attributeType);
        }
        private Dictionary<SpeciesType, Type> RegisterType(Assembly assembly, Type baseType, Type attributeType)
        {
            return assembly.GetTypes().Where(t => IsInheritedFromAnyBaseType(t, baseType) && t.GetCustomAttributes(attributeType, true).Any())
                .Select(t =>
                {
                    PlantZombieAttribute sa = t.GetCustomAttributes(attributeType, false)[0] as PlantZombieAttribute;

                    return new KeyValuePair<SpeciesType, Type>(sa.SpeciesType, t);

                }).ToDictionary(t => t.Key, t => t.Value);
        }
       
        private static bool IsInheritedFromAnyBaseType(Type type, Type baseTypes)
        {
            while (type != null)
            {
                if (baseTypes == type.BaseType)
                {
                    return true;
                }
                type = type.BaseType;
            }
            return false;
        }
        #endregion
    }
}
